ActiveReports 9 > ActiveReports User Guide > Samples and Walkthroughs > Walkthroughs > Page Report/RDL Report Walkthroughs > Data > Reports with Parameterized Queries |
You can create dynamic queries to change the structure of a query at run time. This advanced walkthrough illustrates how to create a simple dynamic query.
The walkthrough is split into the following activities:
Note:
|
When you complete this walkthrough you get a layout that looks similar to the following at design time and at runtime.
To add an ActiveReport to the Visual Studio project
See Adding an ActiveReport to a Project for information on adding different report layouts.
To connect the report to a data source
To add a dataset
SQL Query |
Copy Code
|
---|---|
SELECT Movie.Title, Product.InStock, Product.StorePrice FROM MediaType INNER JOIN (Movie INNER JOIN (Product INNER JOIN MovieProduct ON Product.ProductID = MovieProduct.ProductID) ON Movie.MovieID = MovieProduct.MovieID) ON MediaType.MediaID = MovieProduct.MediaType WHERE (((MediaType.MediaID)=1)) ORDER BY Movie.Title |
To create a layout for the report
Property Name | Property Value |
---|---|
Location | 0in, 0.5in |
Size | 5.5in, 0.75in |
FixedSize (only for FixedPageLayout reports) | 6.5in, 7in |
Data Field | Column Name |
---|---|
Title | TableColumn1 |
InStock | TableColumn2 |
StorePrice | TableColumn3 |
Note: This automatically places an expression in the detail row and simultaneously places a static label in the header row of the same column. |
Property Name | Property Value |
---|---|
FontWeight | Bold |
BackgroundColor | DarkSeaGreen |
RepeatOnNewPage | True |
Select the StorePrice field in the detail row and in the Properties Window, set its Format property to Currency.
Column | Width |
---|---|
First | 4.5in |
Second | 1in |
Third | 1in |
To create a second dataset for use by the parameter list
SQL Query |
Copy Code
|
---|---|
SELECT 0 AS MediaID, "All" AS Description
FROM MediaType
UNION SELECT MediaID, Description
FROM MediaType
ORDER BY Description
|
To add parameters to the report
In the General tab:
In the Available Values tab select From query:
To modify the Products dataset to use a dynamic query
Query |
Copy Code
|
---|---|
="SELECT Movie.Title, Product.InStock, Product.StorePrice, MediaType.Description FROM MediaType INNER JOIN (Movie INNER JOIN (Product INNER JOIN MovieProduct ON Product.ProductID = MovieProduct.ProductID) ON Movie.MovieID = MovieProduct.MovieID) ON MediaType.MediaID = MovieProduct.MediaType" & IIf(Parameters!MediaType.Value = 0, ""," WHERE (MediaType = " & Parameters!MediaType.Value & ")") & " ORDER BY Movie.Title" |
To add a header to display the chosen parameter label
Property Name | Property Value |
---|---|
TextAlign | Center |
FontSize | 14pt |
Location | 0in, 0in |
Size | 6.5in, 0.25in |
Value | =Parameters!MediaType.Label & " Movies in Stock" |
Note: Using Label instead of Value in the expression displays a more readily understandable Description field instead of the MediaID field we used for the parameter's value. |
To view the report
OR